<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <%@include file="/res/include/base-head.jsp"%>
	<%@include file="/res/include/jquery-easyui.jsp"%>
	<script type="text/javascript" src="${pageContext.request.contextPath}/res/js/sales/sales.js"></script>
  </head>
  <body>  
<div class="page_title clearfix">
    <h2>
    <c:if test="${!empty salesBaseVo}">
    	编辑
    </c:if>
    <c:if test="${empty salesBaseVo}">
    	新增
    </c:if>
    </h2>
</div>
<div class="form_item topic_add">
   <form id="data-form">
   	<c:if test="${!empty salesBaseVo}">
    	<input type="hidden" name="id" value="${salesBaseVo.id }"/>
    </c:if>
    <dl>
        <dt>促销对象(范围)：</dt>
        <dd>
        	<select class="txt grid-20"  name="target" id="target" onchange="changeTarget(this.value)">
				<option value="1"
					<c:if test="${salesBaseVo != null && salesBaseVo.target==1}"> selected="selected"</c:if>
				>指定店铺</option>
				<option value="2"
					<c:if test="${salesBaseVo != null && salesBaseVo.target==2}"> selected="selected"</c:if>
				>邻里店铺</option>
				<option value="2"
					<c:if test="${salesBaseVo != null && salesBaseVo.target==3}"> selected="selected"</c:if>
				>社区店铺</option>
			</select>
        </dd>
    </dl>
    <dl id="selectShop">
      	 <dt>店铺：</dt>
         <dd>
         <select class="txt grid-20" name="shopId">
			<option value="">--请选择--</option>
        	<c:forEach var="shopVo" items="${shopList}">
        		<option value="${shopVo.id }">${shopVo.name }</option>
        	</c:forEach>
		</select>
         </dd>
    </dl>
    <dl>
        <dt>活动类型：</dt>
        <dd>
        	<select name="type">
				<option value="1"
					<c:if test="${salesBaseVo != null && salesBaseVo.type==1}"> selected="selected"</c:if>
				>满减</option>
				<option value="2"
					<c:if test="${salesBaseVo != null && salesBaseVo.type==2}"> selected="selected"</c:if>
				>买赠</option>
			</select>
        </dd>
    </dl>
    <dl>
        <dt>补贴类型：</dt>
        <dd>
        	<select name="subsidyType">
				<option value="1"
					<c:if test="${salesBaseVo != null && salesBaseVo.subsidyType==1}"> selected="selected"</c:if>
				>商家补贴</option>
				<option value="2"
					<c:if test="${salesBaseVo != null && salesBaseVo.subsidyType==2}"> selected="selected"</c:if>
				>圈圈补贴</option>
			</select>
        </dd>
    </dl>
    <dl>
        <dt>名称：</dt>
        <dd><input type="text" name="name" value="${salesBaseVo.name }" class="txt grid-25 easyui-validatebox" data-options="required:true" maxlength="32"/></dd>
    </dl>
    <dl>
        <dt>触发条件：</dt>
        <dd><input type="text" name="requirement" value="${salesBaseVo.requirement }" class="txt grid-15 easyui-numberbox" min="1" max="1000" precision="0" data-options="required:true" maxlength="5"/></dd>
    </dl>
    <dl>
        <dt>补贴让利：</dt>
        <dd><input type="text" name="subsidy" value="${salesBaseVo.subsidy }" class="txt grid-15 easyui-numberbox" min="1" max="1000" precision="0" data-options="required:true" maxlength="5"/></dd>
    </dl>
    <dl>
        <dt>开始时间：</dt>
        <dd>
        	<fmt:formatDate var="startAt" value="${salesBaseVo.startAt}" pattern="yyyy-MM-dd HH:mm:ss"/>
        	<input id="startAt" type="text" class="txt easyui-datetimebox grid-15" name="startAt" value="${startAt}" data-options="required:false,validType:'datetime'" />
        </dd>
    </dl>
    <dl>
        <dt>结束时间：</dt>
        <dd>
        	<fmt:formatDate var="endAt" value="${salesBaseVo.endAt}" pattern="yyyy-MM-dd HH:mm:ss"/>
        	<input id="endAt" type="text" class="txt easyui-datetimebox grid-15" name="endAt" value="${endAt}" data-options="required:false,validType:'datetime'" />
        </dd>
    </dl>
    <dl>
        <dt>状态：</dt>
        <dd>
        	<select name="status">
				<option value="1"
					<c:if test="${salesBaseVo != null && salesBaseVo.status==1}"> selected="selected"</c:if>
				>有效</option>
				<option value="2"
					<c:if test="${salesBaseVo != null && salesBaseVo.status==2}"> selected="selected"</c:if>
				>失效</option>
			</select>
        </dd>
    </dl>
    </form>
    <p class="page_btn"><input type="button" id="doSave" value="保存" class="btn_blue" onclick="doSave();"/></p>
</div>
<script type="text/javascript">
$(document).ready(function() {
	<c:if test="${!empty salesBaseVo}">
		if('${salesBaseVo.target}' != 1){
			$('#selectShop').hide();
		}
	</c:if>
});
function changeTarget(target){
	if(target == 1){
		$('#selectShop').show();
	}else if(target == 2 || targer == 3){
		$('#selectShop').hide();
	}
}
var isSave = false;
//提交保存
function doSave(){
	var url = contextPath+'/sales/base/add';
	<c:if test="${!empty salesBaseVo}">
		url = contextPath+'/sales/base/update';
	</c:if>
	if(!$('#data-form').form('validate')) return;
	if (isSave) {
		return;
	}
	isSave = true;
	var data = $('#data-form').form('jsonObject');
	console.info("------------:"+JSON.stringify(data));
	$.post(url,data,function(result) {
		if(result.code==1) {
			top.showInfo('保存成功');
		} else {
			isSave = false;
			top.showInfo('保存失败:'+result.msg);
		}
	},'json');
}
</script>
  </body>
</html>
